package com.styytech.dadabao.ui.home;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;

import com.lidroid.xutils.view.annotation.ContentView;
import com.styytech.dadabao.R;
import com.styytech.dadabao.base.BaseActivity;
import com.styytech.dadabao.constant.ConstantsCommon;
import com.styytech.dadabao.constant.ConstantsServerUrl;
import com.styytech.dadabao.ui.project.ProjectFragment;

/**
 * Created by User on 2015/9/7.
 */
@ContentView(R.layout.activity_project_list)
public class ProjectListActivity extends BaseActivity {

    Context context;

    /**
     * 用于对Fragment进行管理
     */
    private FragmentManager fragmentManager;
    private FragmentTransaction transaction;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initData();
    }

    private void initData() {
        context = this;
        setTopBar("项目", View.VISIBLE, View.VISIBLE, "返回");
        fragmentManager = getSupportFragmentManager();
        // 开启一个Fragment事务
        getDataList();
    }

    public void getDataList() {
        transaction = fragmentManager.beginTransaction();
        String newsUrl = ConstantsServerUrl.getProductListUrl();
        addFragment(ProjectFragment.newInstance(newsUrl,
                ConstantsCommon.DATA_SRC_PROJECT,
                ConstantsCommon.ADAPTER_TYPE_PROJECT, null));
    }

    private void addFragment(Fragment fragment) {
        transaction.replace(R.id.fl_content, fragment);
        transaction.commit();
    }
}
